﻿package view.mainUI.mainBottom.ui
{
    import com.core.*;
    import com.greensock.*;
    import com.sh.game.consts.*;
    import com.sh.game.display.*;
    import com.sh.game.global.*;
    import control.*;
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import morn.core.handlers.*;
    import uiresource.*;
    import view.*;
    import view.mainUI.mainBottom.controller.*;

    public class MainBottom extends MainBottomUI
    {
        private var _hpMc:XMLMovieClip;
        private var _mpMc:XMLMovieClip;
        private var _surfaceMcHp:XMLMovieClip;
        private var _surfaceMcMp:XMLMovieClip;
        private var _rect1:Sprite;
        private var _rect2:Sprite;
        private var _rect3:Sprite;
        private var _rect4:Sprite;
        public var _bloodTop:Sprite;
        public var expTop:Sprite;
        public var rbobj:Object;
        private var mSkillControl:MainSkillControl;
        private var _menuControl:MenuControl;
        private var mExpTweenControl:MainExpTweenControl;
        private var mSmallHpMask:Sprite;
        private var mSmallMpMask:Sprite;
        public var chatTip:ChatTip;
        private var objArr:Object;
        private var _anger:Number = 0;
        private var _angerValue:int = 0;
        private var _loadFireing:Boolean = false;
        private var _cfgGuide:Object;
        private var _cfgGuide1:Object;
        public static var mpmark:Class = MainBottom_mpmark;
        public static var hpmark:Class = MainBottom_hpmark;
        public static const blood_eff:Class = MainBottom_blood_eff;
        public static const redface:Class = MainBottom_redface;
        public static const blue_face:Class = MainBottom_blue_face;
        public static const hp_eff:Class = MainBottom_hp_eff;
        public static const mp_eff:Class = MainBottom_mp_eff;
        public static const fire:Class = MainBottom_fire;
        public static const anger:Class = MainBottom_anger;
        public static const surface:Class = MainBottom_surface;
        public static const eye:Class = MainBottom_eye;
        public static const vipmc:Class = MainBottom_vipmc;

        public function MainBottom()
        {
            this.objArr = {};
            this._cfgGuide1 = ConfigDictionary.data.newguide;
            return;
        }// end function

        public function get menuControl() : MenuControl
        {
            return this._menuControl;
        }// end function

        public function get angerValue() : int
        {
            return this._angerValue;
        }// end function

        override protected function initialize() : void
        {
            var _loc_2:Object = null;
            var _loc_3:String = null;
            var _loc_4:Array = null;
            super.initialize();
            this._bloodTop = new Sprite();
            large.addChild(this._bloodTop);
            this._bloodTop.graphics.beginFill(0, 0);
            this._bloodTop.graphics.drawCircle(imgHp.width, imgHp.height / 2, imgHp.width);
            this._bloodTop.graphics.endFill();
            this._bloodTop.x = imgHp.x;
            this._bloodTop.y = imgHp.y;
            this.expTop = new Sprite();
            large.addChild(this.expTop);
            this.expTop.graphics.beginFill(0, 0);
            this.expTop.graphics.drawRect(0, 0, expLight2.width, expLight2.height);
            this.expTop.graphics.endFill();
            this.expTop.x = expLight2.x;
            this.expTop.y = expLight2.y;
            this.loadHpClip();
            var _loc_1:* = new MainBottomControl(this);
            ModelProxy.addObserver("mainview", _loc_1);
            ModelProxy.addObserver("business", _loc_1);
            this.updateAnger();
            this.mSkillControl = new MainSkillControl(this);
            this._menuControl = new MenuControl(this);
            this.mExpTweenControl = new MainExpTweenControl(this);
            addEventListener(MouseEvent.MOUSE_DOWN, this.mouseDownHandler);
            this._menuControl.init();
            if (this._cfgGuide == null)
            {
                this._cfgGuide = ConfigDictionary.data.guideplugin;
                if (this._cfgGuide["main"])
                {
                    for each (_loc_2 in this._cfgGuide["main"])
                    {
                        
                        if (this.hasOwnProperty(_loc_2.eventparam))
                        {
                            this[_loc_2.eventparam].gname = _loc_2.eventparam;
                            ModelProxy.change("guideitem", "guideid" + _loc_2.id, this[_loc_2.eventparam]);
                            if (!this.objArr[_loc_2.eventparam])
                            {
                                this.objArr[_loc_2.eventparam] = new Array();
                            }
                            this.objArr[_loc_2.eventparam][_loc_2.id] = _loc_2.id;
                        }
                    }
                    for (_loc_3 in this.objArr)
                    {
                        
                        _loc_4 = this.objArr[_loc_3];
                        if (_loc_4.length > 0)
                        {
                            this[_loc_3].addEventListener(MouseEvent.CLICK, this.clickHandler);
                        }
                    }
                }
            }
            this.chatTip = new ChatTip();
            large.addChild(this.chatTip);
            this.chatTip.x = 275;
            this.chatTip.y = -40;
            return;
        }// end function

        private function clickHandler(event:Event) : void
        {
            var _loc_3:int = 0;
            var _loc_2:* = this.objArr[event.currentTarget.gname];
            for each (_loc_3 in _loc_2)
            {
                
                if (this._cfgGuide1[_loc_3].event == 6)
                {
                    if (GuideViewPao.getInstance().gid == _loc_3)
                    {
                        GuideViewPao.getInstance().hide();
                    }
                    continue;
                }
                ModelProxy.change("guide", "hide", _loc_3);
            }
            return;
        }// end function

        public function removeChatTips(param1:int) : void
        {
            this.chatTip.updateRemove(param1);
            return;
        }// end function

        public function changeChatTips(param1:int, param2:Object) : void
        {
            this.chatTip.updateChange(param1, param2);
            return;
        }// end function

        private function mouseDownHandler(event:MouseEvent) : void
        {
            var _loc_2:Point = null;
            var _loc_3:uint = 0;
            var _loc_4:uint = 0;
            if (this.bg.bitmapData)
            {
                _loc_2 = this.bg.globalToLocal(new Point(event.stageX, event.stageY));
                _loc_3 = this.bg.bitmapData.getPixel32(_loc_2.x, _loc_2.y);
                _loc_4 = _loc_3 >> 24;
                if (_loc_4 == 0)
                {
                    return;
                }
            }
            return;
        }// end function

        private function loadHpClip() : void
        {
            App.leisureMloader.loadSWF(Config.getUrl("assets/images/mainui/bloodmovie.swf", ResourceType.NORMAL), 1, new Handler(this.mcLoaded));
            return;
        }// end function

        private function mcLoaded(param1) : void
        {
            var _loc_2:* = this.imgHp.parent.getChildIndex(this.imgHp);
            var _loc_3:* = new XML(new hp_eff());
            this._hpMc = new XMLMovieClip("png.bloodmovie.hp_effect", _loc_3);
            this._hpMc.play();
            this._hpMc.x = imgHp.x;
            this._hpMc.y = imgHp.y;
            this._hpMc.interval = 1000 / 12;
            large.addChildAt(this._hpMc, _loc_2);
            var _loc_4:* = new XML(new mp_eff());
            this._mpMc = new XMLMovieClip("png.bloodmovie.mp_effect", _loc_4);
            this._mpMc.transform.colorTransform = new ColorTransform(1, 1, 1, 1, 51 * 0.24, 204 * 0.24, 255 * 0.24);
            this._mpMc.play();
            this._mpMc.x = imgMp.x - 40;
            this._mpMc.y = imgMp.y;
            this._mpMc.interval = 1000 / 12;
            var _loc_5:* = this.imgMp.parent.getChildIndex(this.imgMp);
            large.addChildAt(this._mpMc, _loc_5);
            this._rect3 = new Sprite();
            this._rect4 = new Sprite();
            this.addChild(this._rect3);
            this.addChild(this._rect4);
            this._rect3.graphics.beginFill(16777215, 1);
            this._rect3.graphics.drawRect(0, 0, 100, 100);
            this._rect3.graphics.endFill();
            this._rect4.graphics.beginFill(16777215, 1);
            this._rect4.graphics.drawRect(0, 0, 100, 100);
            this._rect4.graphics.endFill();
            this._rect3.x = 66;
            this._rect4.x = 100;
            this._rect3.y = 30;
            this._rect4.y = 30;
            this._hpMc.mask = this._rect3;
            this._mpMc.mask = this._rect4;
            _loc_2 = this._hpMc.parent.getChildIndex(this._hpMc);
            _loc_3 = new XML(new redface());
            this._surfaceMcHp = new XMLMovieClip("png.bloodmovie.redface", _loc_3);
            this._surfaceMcHp.play();
            this._surfaceMcHp.x = this._hpMc.x - 11 + 16;
            this._surfaceMcHp.interval = 125;
            large.addChildAt(this._surfaceMcHp, (_loc_2 + 1));
            this._surfaceMcHp.y = this._rect3.y - 27;
            var _loc_6:* = new hpmark();
            new hpmark().x = 67;
            _loc_6.y = 31;
            large.addChild(_loc_6);
            imgHp.parent.removeChild(imgHp);
            this._surfaceMcHp.mask = _loc_6;
            _loc_5 = this._mpMc.parent.getChildIndex(this._mpMc);
            _loc_3 = new XML(new blue_face());
            this._surfaceMcMp = new XMLMovieClip("png.bloodmovie.blue_face", _loc_3);
            this._surfaceMcMp.play();
            this._surfaceMcMp.x = this._mpMc.x + 40;
            this._surfaceMcMp.frame = 3;
            this._surfaceMcMp.interval = 125;
            large.addChildAt(this._surfaceMcMp, (_loc_5 + 1));
            this._surfaceMcMp.y = this._rect4.y - 27;
            var _loc_7:* = new mpmark();
            new mpmark().x = 106;
            _loc_7.y = 31;
            large.addChild(_loc_7);
            imgMp.parent.removeChild(imgMp);
            this._surfaceMcMp.mask = _loc_7;
            if (this.rbobj)
            {
                this.updateHPMp(this.rbobj);
            }
            return;
        }// end function

        public function setHp(param1:Number) : void
        {
            var _loc_2:* = 30 + (1 - param1) * 95;
            if (this._rect3)
            {
                TweenLite.to(this._rect3, 1.5, {y:_loc_2});
            }
            if (this._surfaceMcHp)
            {
                TweenLite.to(this._surfaceMcHp, 1.5, {y:_loc_2 - 27});
            }
            return;
        }// end function

        public function setMp(param1:Number) : void
        {
            var _loc_2:* = 30 + (1 - param1) * 95;
            if (this._rect4)
            {
                TweenLite.to(this._rect4, 1.5, {y:_loc_2});
            }
            if (this._surfaceMcMp)
            {
                TweenLite.to(this._surfaceMcMp, 1.5, {y:_loc_2 - 27});
            }
            return;
        }// end function

        public function dataUserUpdate() : void
        {
            this.updateAnger();
            this.updateExp();
            return;
        }// end function

        public function updateExp() : void
        {
            var _loc_1:* = ConfigDictionary.data.level[UserData.getUserData("level")];
            var _loc_2:* = UserData.getUserData();
            if (_loc_2.hasOwnProperty("exp"))
            {
                this.mExpTweenControl.updateExp();
            }
            return;
        }// end function

        public function updateAnger(param1:int = -1) : void
        {
            var _loc_2:Object = null;
            if (param1 < 0)
            {
                _loc_2 = UserData.getUserData();
                if (_loc_2 && _loc_2.hasOwnProperty("anger"))
                {
                    this._angerValue = _loc_2.anger;
                }
            }
            else
            {
                this._angerValue = param1;
            }
            return;
        }// end function

        public function updateHPMp(param1:Object) : void
        {
            this.rbobj = param1;
            if (param1 == null)
            {
                this.setHp(1);
                this.setMp(1);
            }
            else
            {
                this.setHp(int(param1.hp) / int(param1.maxHp));
                this.setMp(int(param1.mp) / int(param1.maxMp));
            }
            return;
        }// end function

        private function loadFire() : void
        {
            return;
        }// end function

        private function angerLoaded(param1) : void
        {
            return;
        }// end function

    }
}
